(function () {
    var LoadNormal = (function () {
        function LoadNormal() {
            LoadNormal.super(this);

            this.loadUI = null;

            this.init();
        }
        Laya.class(LoadNormal, "", Laya.Sprite);
        var _proto = LoadNormal.prototype;
        _proto.init = function () {
            this.size(GAME_CONFIG.WIDTH, Laya.stage.height);

            var loadUI = utils.createSkeleton("res/load/loading_normal");
                loadUI.pos(GAME_CONFIG.WIDTH / 2, Laya.stage.height / 2);
            this.loadUI = loadUI;
            this.addChild(loadUI);
        }

        _proto.load = function (assets, addScene, callback) {
            this.loadUI.play("enter", false);
            this.loadUI.once(Laya.Event.STOPPED, this, function () {
                this.loadUI.play("loop", true);
                Laya.loader.load(assets, Laya.Handler.create(this, function () {
                    console.log("====资源加载完成=====");
                    addScene();
                    this.loadUI.play("exit", false);
                    this.loadUI.once(Laya.Event.STOPPED, this, function () {
                        callback();
                    });
                }));
            });
        }
        _proto.onResize = function (height) {
            this.height = height;

            this.loadUI.y = height / 2;
        }

        return LoadNormal;
    })();

    var LoadSimple = (function () {
        function LoadSimple() {
            LoadSimple.super(this);

            this.UIMask = null;
            this.loadUI = null;

            this.init();
        }
        Laya.class(LoadSimple, "", Laya.Sprite);
        var _proto = LoadSimple.prototype;
        _proto.init = function () {
            this.size(GAME_CONFIG.WIDTH, Laya.stage.height);

            var UIMask = new Laya.Image("res/public/mask.png");
                UIMask.alpha = 0.3;
                UIMask.size(GAME_CONFIG.WIDTH, GAME_CONFIG.WIDTH);
                UIMask.centerX = 0;
                UIMask.centerY = 0;

            var loadUI = utils.createSkeleton("res/load/loading_small");
                loadUI.pos(GAME_CONFIG.WIDTH / 2, Laya.stage.height / 2);

            this.UIMask = UIMask;
            this.loadUI = loadUI;
            this.addChildren(UIMask, loadUI);
        }

        _proto.load = function (assets, addScene, callback) {
            this.loadUI.play("loading", true);
            Laya.loader.load(assets, Laya.Handler.create(this, function () {
                addScene();
                //callback();
                setTimeout(callback, 0);
            }));
        }
        _proto.onResize = function (height) {
            this.height = height;

            this.UIMask.centerY = 0;
            this.loadUI.y = height / 2;
        }

        return LoadSimple;
    })();

    (function () {
        function LoadScene() {
            LoadScene.super(this);

            this.loadNormal = null;
            this.loadSimple = null;

            this.init();
        }
        Laya.class(LoadScene, "Libs.LoadScene", Laya.Sprite);
        var _proto = LoadScene.prototype;
        _proto.init = function () {
            this.size(GAME_CONFIG.WIDTH, Laya.stage.height);

            this.mouseEnabled = true;
            
            this.loadNormal = new LoadNormal();
            this.loadSimple = new LoadSimple();
        }

        _proto.onResize = function (height) {
            this.height = height;

            this.loadNormal.onResize(height);
            this.loadSimple.onResize(height);
        }
        _proto.load = function (config, addScene, nextScene) {
            this.removeChildren();
            var type = "";
            switch(config.TYPE){
                case "normal":
                    type = "loadNormal";
                    //this.addChild(this.loadNormal);
                    //this.loadNormal.load(config.ASSETS, callback);
                    break;
                case "simple":
                    type = "loadSimple";
                    //this.addChild(this.loadSimple);
                    //this.loadSimple.load(config.ASSETS, callback);
                    break;
            }

            this.addChild(this[type]);
            this[type].load(config.RES, addScene, function () {
                this.removeSelf();
                nextScene();
            }.bind(this));
        }
    })();
})();